<template>
	<view>
		<view class="customer-list-viewportal">
			<view class="tui-searchbox">
				<view :style="{height: `${statusBar.top}px`, width: '100%'}"></view>
				<view class="tui-search-bar" :style="{height: `${statusBar.height}px`}">
					<tui-icon name="arrowleft" color="#FFF" :size="32" @tap="backToHome"></tui-icon>
					<view class="tui-search-input" :style="{marginRight: `${statusBar.menuWidth}px`}">
						<icon type="search" :size="13" color="#999"></icon>
						<input type="text" v-model="inpName" @confirm="inpConfirm" class="tui-search-input" confirm-type="search" placeholder="输入下级名称" />
					</view>
				</view>
			</view>
			<view class="banner-bg">
				<view class="tui-primary-bg tui-route-left"></view>
				<view class="tui-primary-bg tui-route-right"></view>
				<view class="tui-entry-pane">
					<view class="entry-item">
						<view class="customer-num">
							{{total}}
						</view>
						<view class="entry-txt">
							下级数量
						</view>
					</view>
					<view class="entry-item" @tap="toInvitation">
						<view class="entry-icon">
							<image src="https://cwmall.oss-cn-shanghai.aliyuncs.com/mp-icon/proxy/share.png" class="icon-image" mode="aspectFill"></image>
						</view>
						<view class="entry-txt">
							下级拓展
						</view>
					</view>
				</view>
			</view>
			<view class="body-wrapper">
				<view class="customer-list">
					<block v-if="dataList && dataList.length">
						<tui-list-cell padding="0" :lineLeft="false" :arrow="false" v-for="item in dataList" :key="item.customerId">
							<view class="tui-list-cell">
								<view class="avatar">
									<image class="avatar-img" :src="item.avatarUrl" mode="aspectFill"></image>
								</view>
								<view class="content">
									<view class="user-name">
										<view>{{item.nickName || '未知用户'}}</view>
										<view class="amount-txt">
											订单总数: {{item.totalOrderNum || 0}}
										</view>
									</view>
									<view class="phone-number">
										<view></view>
										<view class="amount-txt">
											订单总金额: {{item.totalOrderAmount || 0}}
										</view>
									</view>
								</view>
							</view>
						</tui-list-cell>
					</block>
					<block v-else>
						<tui-no-data :fixed="false" imgUrl="https://cwmall.oss-cn-shanghai.aliyuncs.com/mp-icon/img_noorder_3x.png">暂无下级记录</tui-no-data>
					</block>
					<uni-load-more :status="moreStatus" v-if="listData.length"></uni-load-more>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { LoadMore } from '@/constants'
	
	export default {
		data() {
			return {
				inpName: '',
				total: 0,
				dataList: [],
				moreStatus: LoadMore.noop
			}
		},
		computed: {
			statusBar() {
				const { systemInfo: { statusBarHeight } } = this.$store.state
				const menu = uni.getMenuButtonBoundingClientRect()
				return {
					top: statusBarHeight + (menu.top - statusBarHeight),
					height: menu.height + (menu.top - statusBarHeight),
					menuWidth: menu.width + uni.upx2px(14)
				}
			}
		},
		mounted() {
			this.datas = {
				pagination: {
					pageNum: 1,
					pageSize: 20
				}
			}
			this.getBranchs()
		},
		methods: {
			backToHome() {
				uni.navigateBack({
					url: '/pagesA/home/home'
				})
			},
			toInvitation() {
				uni.navigateTo({
					url: '/pagesA/invitation/invitation?type=branchs'
				})
			},
			inpConfirm() {
				this.datas.pagination.pageNum = 1
				uni.showLoading()
				this.getBranchs()
			},
			async getBranchs() {
				const { pagination: { pageNum, pageSize } } = this.datas
				const { data, success, total } = await this.$api.getLowLevelList({
					merchantId: this.$store.state.merchantId,
					nickName: this.inpName,
					pageNum,
					pageSize
				})
				this.total = total
				// this.dataList = data
				if (pageNum === 1) {
					this.dataList = data
				} else {
					if (data && data.length) {
						this.dataList = this.dataList.concat(data)
					} else {
						this.moreStatus = LoadMore.nomore
					}
				}
				uni.hideLoading()
			}
		},
		onReachBottom() {
			if (![LoadMore.nomore, LoadMore.loading].includes(this.moreStatus)) {
				this.moreStatus = LoadMore.loading
				this.datas.pagination.pageNum++
				this.getBranchs()
			}
		}
	}
</script>

<style lang="scss">
page {
	background-color: #f7f7f7;
}
.customer-list-viewportal {
	.tui-searchbox {
		width: 100%;
		padding: 0 30rpx 10rpx 0;
		box-sizing: border-box;
		background: #e41f19;
		border-bottom: 1px solid #ddd;
		/* #ifdef H5 */
		top: 44px;
		/* #endif */
		&::after {
			content: '';
			position: absolute;
			border-bottom: 1rpx solid #d2d2d2;
			-webkit-transform: scaleY(0.5);
			transform: scaleY(0.5);
			bottom: 0;
			right: 0;
			left: 0;
		}
		.tui-search-bar {
			height: 60rpx;
			display: flex;
			align-items: center;
			.tui-search-input {
				width: 100%;
				height: 60rpx;
				background: #f1f1f1;
				border-radius: 30rpx;
				font-size: 26rpx;
				color: #999;
				display: flex;
				align-items: center;
				justify-content: flex-start;
				margin-left: 20rpx;
				padding-left: 30rpx;
				.tui-search-input {
					flex: 1;
					padding: 0;
				}
			}
		}
	}
	.banner-bg {
		display: flex;
		height: 140rpx;
		background-color: #e41f19;
		position: relative;
		margin-top: -10rpx;
		padding-top: 2rpx;
		.tui-primary-bg {
			width: 50%;
			display: inline-block;
			height: 175rpx;
			border: 1px solid transparent;
			position: relative;
			z-index: 1;
			background-color: #e41f19;
		}
		.tui-route-left {
			transform: skewY(8deg);
		}
		.tui-route-right {
			transform: skewY(-8deg);
		}
		.tui-entry-pane {
			position: absolute;
			left: 30rpx;
			right: 30rpx;
			bottom: -80rpx;
			height: 160rpx;
			background: #fff;
			border-radius: 12rpx;
			overflow: hidden;
			z-index: 99;
			box-shadow: 0 3rpx 20rpx rgba(183, 183, 183, 0.1);
			padding: 30rpx;
			display: flex;
			justify-content: space-around;
			.entry-item {
				.customer-num {
					font-size: 40rpx;
					font-weight: bold;
					text-align: center;
					height: 70rpx;
				}
				.entry-txt {
					font-size: 28rpx;
					color: #333;
				}
				.entry-icon {
					text-align: center;
					font-size: 0;
					height: 70rpx;
					.icon-image {
						width: 60rpx;
						height: 60rpx;
					}
				}
			}
		}
	}
	.body-wrapper {
		padding: 120rpx 30rpx 0;
		.customer-list {
			background: #FFF;
			border-radius: 14rpx;
			overflow: hidden;
			.tui-list-cell {
				display: flex;
				align-items: center;
				padding: 20rpx 60rpx 20rpx 20rpx;
				width: 100%;
				.avatar {
					border-radius: 14rpx;
					width: 80rpx;
					height: 80rpx;
					background: #eee;
					.avatar-img {
						width: 80rpx;
						height: 80rpx;
					}
				}
				.content {
					flex: 1;
					width: 0;
					overflow: hidden;
					padding: 0 0 0 20rpx;
					.amount-txt {
						font-size: 24rpx;
						color: #666;
					}
					.user-name {
						text-overflow: ellipsis;
						white-space: nowrap;
						overflow: hidden;
						width: 100%;
						display: flex;
						justify-content: space-between;
					}
					.phone-number {
						font-size: 24rpx;
						color: #666;
						display: flex;
						justify-content: space-between;
					}
				}
			}
		}
	}
	
}
</style>
